	
	package servlet.course;
	
	import java.io.IOException;
	import javax.servlet.ServletException;
	import javax.servlet.http.HttpServlet;
	import javax.servlet.http.HttpServletRequest;
	import javax.servlet.http.HttpServletResponse;
	import service.CourseManager;
	import enitys.Course;
		
	public class AddCourse extends HttpServlet {
	
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

		/**
		 * Constructor of the object.
		 */
		public AddCourse() {
			super();
		}
	
		
		/**
		 * The doGet method of the servlet. <br>
		 *
		 * This method is called when a form has its tag value method equals to get.
		 * 
		 * @param request the request send by the client to the server
		 * @param response the response send by the server to the client
		 * @throws ServletException if an error occurred
		 * @throws IOException if an error occurred
		 */
		public void doGet(HttpServletRequest request, HttpServletResponse response)
				throws ServletException, IOException {
				doPost(request,response);
		}
	
		/**
		 * The doPost method of the servlet. <br>
		 *
		 * This method is called when a form has its tag value method equals to post.
		 * 
		 * @param request the request send by the client to the server
		 * @param response the response send by the server to the client
		 * @throws ServletException if an error occurred
		 * @throws IOException if an error occurred
		 */
		public void doPost(HttpServletRequest request, HttpServletResponse response)
				throws ServletException, IOException {
			int id=Integer.parseInt(request.getParameter("id"));
			String name=request.getParameter("cname");
			String teacher=request.getParameter("teacher");
			String score=request.getParameter("score");
			Course course=new Course();
			course.setC_id(id);
			course.setC_name(name);
			course.setTeacher(teacher);
			course.setScore(score);
			CourseManager manger=CourseManager.getInstance();
			boolean flag=manger.AddCourse(course);
			if(flag){
				request.setAttribute("message", "添加成功");
				request.getRequestDispatcher("/servlet/GradeAllInfo").forward(request, response);
			}
		}
	}
